package vip.xiaonuo.device.vo;

import com.alibaba.fastjson.JSONObject;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Result {
    private String errmsg;
    private boolean succ;
    private Object result;

    private Integer code;

    public static Result ok() {
        return Result.builder().succ(true).errmsg("success").code(200).build();
    }

    public static Result ok(Object result) {
        return Result.builder().succ(true).errmsg("success").result(result).code(200).build();
    }

    public static Result fail(String errmsg) {
        return Result.builder().succ(false).errmsg(errmsg).code(500).build();
    }

    public static Result fail(Integer code, String errmsg) {
        return Result.builder().succ(false).errmsg(errmsg).code(code).build();
    }

    public String toJsonStr() {
        return JSONObject.toJSONString(this);
    }
}
